using System.Collections.Generic;
using System.Reflection;
using GameLogic;
using GameConfig;
#if ENABLE_OBFUZ
using Obfuz;
#endif
using TEngine;
#pragma warning disable CS0436


/// <summary>
/// 游戏App。
/// </summary>
#if ENABLE_OBFUZ
[ObfuzIgnore(ObfuzScope.TypeName | ObfuzScope.MethodName)]
#endif
public partial class GameApp
{
    private static List<Assembly> _hotfixAssembly;

    /// <summary>
    /// 热更域App主入口。
    /// </summary>
    /// <param name="objects"></param>
    public static void Entrance(object[] objects)
    {
        GameEventHelper.Init();
        _hotfixAssembly = (List<Assembly>)objects[0];
        Log.Warning("======= 看到此条日志代表你成功运行了热更新代码 =======");
        Log.Warning("======= Entrance GameApp =======");
        Utility.Unity.AddDestroyListener(Release);
        Log.Warning("======= StartGameLogic =======");
        // 通过 ConfigSystem.Instance.Tables 访问配置表
        try
        {
            var itemConfig = ConfigSystem.Instance.Tables.TbGeneral.GetOrDefault(1001);
            if (itemConfig != null)
            {
                Log.Warning($"Item Config: {itemConfig.ToString()}");
            }
            else
            {
                Log.Warning("Item 1001 not found in config table");
            }
        }
        catch (System.Exception ex)
        {
            Log.Error($"Failed to load config: {ex.Message}");
        }
        StartGameLogic();
    }
    
    private static void StartGameLogic()
    {
        // GameEvent.Get<ILoginUI>().ShowLoginUI();
        GameModule.UI.ShowUIAsync<BattleMainUI>();
    }
    
    private static void Release()
    {
        // 注意：Release 会在 Unity 对象销毁时被调用（如停止播放、切换场景等）
        // 这是正常行为，不是错误
        Log.Info("======= Release GameApp =======");
        SingletonSystem.Release();
    }
}